<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Manager_Template_Default extends Controller_Template
{
    public $template = 'template/default';

    protected $auth;
    protected $user;    
    protected $styles = array();

    public function before()
    {        
        parent::before();        
        
        Session::instance();

        $this->auth = Auth::instance();     

        if (($this->user = $this->auth->get_user()) === FALSE)
        {
            $this->user = ORM::factory('user');
        }
        
        if($this->auto_render)
        {            
            $this->template->title            = '';
            $this->template->meta_keywords    = '';
            $this->template->meta_description = '';
            $this->template->meta_copywrite   = '';
            $this->template->header           = '';
            $this->template->content          = '';
            $this->template->footer           = '';
            $this->template->scripts          = '';
            $this->template->bind_global('user', $this->user);
        }
    }

    public function after()
    {
        
        $this->template->scripts .= '<script type="text/javascript">BASE_URL = "'.Kohana::$base_url.'";</script>';
        $this->template->scripts .= '<script type="text/javascript">CONTROLLER = "'.$this->request->controller().'/";</script>';
                        
        $scripts = array(Kohana::$base_url.'manager/media/js/jquery.min.js',
                        Kohana::$base_url.'manager/media/js/components/ui/jquery-ui.min.js',
                        //Kohana::$base_url.'manager/media/js/components/checkboxes/iphone.check.js',
                        Kohana::$base_url.'manager/media/js/components/datatables/dataTables.min.js',
                        Kohana::$base_url.'manager/media/js/components/tipsy/jquery.tipsy.js',
                        Kohana::$base_url.'manager/media/js/components/editor/jquery.cleditor.js',
                        Kohana::$base_url.'manager/media/js/components/chosen/chosen.js',
                        Kohana::$base_url.'manager/media/js/components/confirm/jquery.confirm.js',
                        Kohana::$base_url.'manager/media/js/components/validationEngine/jquery.validationEngine.js',
                        Kohana::$base_url.'manager/media/js/components/validationEngine/jquery.validationEngine-pt-br.js',
                        Kohana::$base_url.'manager/media/js/components/checkboxes/customInput.jquery.js',
                        Kohana::$base_url.'manager/media/js/jquery.cookie.js',
                        Kohana::$base_url.'manager/media/js/inheritance.js',
                        Kohana::$base_url.'manager/media/js/app/application.js',
                        Kohana::$base_url.'manager/media/js/app/application/controller/SectionController.js');

        foreach ($scripts as $value) 
        { 
            $this->template->scripts .= '<script language="javascript" src="'.$value.'"></script>';
        }        
        
        parent::after();      
        
    }
} 